package com.glenet.salary.action;

import java.io.IOException;
import java.io.Reader;

import javax.servlet.http.HttpSession;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.glenet.salary.dao.HrUserDao;
import com.glenet.salary.entities.HrUser;
import com.glenet.salary.util.Constant;

/**
 * @author MeiWenhui
 * 
 */
@SuppressWarnings("serial")
public class UserAction extends BaseAction {

	private HrUserDao userDao = new HrUserDao();
	private HrUser user;

	public String signIn() {
		HrUser _user = userDao.signIn(user.getUsername(), user.getPassword());
//		if (_user != null) {
//			HttpSession session = req.getSession();
//			Object object = session.getAttribute(Constant.SESSION_USER);
//			if (object != null) {
//				session.removeAttribute(Constant.SESSION_USER);
//			}
//			session.setAttribute(Constant.SESSION_USER, _user);
//			return SUCCESS;
//		}
		return SUCCESS;
	}

	public HrUser getUser() {
		return user;
	}

	public void setUser(HrUser user) {
		this.user = user;
	}
	
	public static void main(String[] args) throws IOException {
		Reader reader = Resources.getResourceAsReader("ibatis.cfg.xml");
		SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
		System.out.println(sessionFactory);
	}
}
